package cn.fan.whale.service.impl;

import cn.fan.whale.entity.po.DepartmentEntity;
import cn.fan.whale.mapper.DepartmentMapper;
import cn.fan.whale.service.DepartmentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class DepartmentServiceImpl implements DepartmentService {

    private final DepartmentMapper departmentMapper;

    public DepartmentServiceImpl(DepartmentMapper departmentMapper) {
        this.departmentMapper = departmentMapper;
    }

    @Override
    public List<DepartmentEntity> selectBySelective(DepartmentEntity departmentEntity) {
        return departmentMapper.selectBySelective(departmentEntity);
    }

    @Override
    public void save(DepartmentEntity departmentEntity) {
        Date nowDate = new Date();
        departmentEntity.setCtime(nowDate);
        departmentEntity.setMtime(nowDate);
        departmentEntity.setAvailable(1);
        departmentMapper.insert(departmentEntity);
    }

    @Override
    public void update(DepartmentEntity departmentEntity) {
        Date nowDate = new Date();
        departmentEntity.setMtime(nowDate);
        departmentMapper.updateByPrimaryKeySelective(departmentEntity);
    }

    @Override
    public void delete(Integer deptId) {
        departmentMapper.deleteByPrimaryKey(deptId);
    }
}
